<?php
/**
 * 自定义函数
 * ＃＃＃＃＃＃＃＃＃＃＃＃＃＃＃＃＃＃＃＃＃＃＃＃＃＃＃＃＃＃＃＃＃＃＃＃＃＃＃
 * 自定义函数或扩展函数的写法参见：
 * http://www.th7.cn/Program/php/201303/129826.shtml
 * 加载此扩展时使用：
 * $this->load->helper('myjsonfunc');
 * 
 * 
 * $json_$url_base 参见配置文件 myconfig.php
 * 
 */



/**
 * 发送post请求
 */
function postData($url, $data){
	$ch = curl_init();
	curl_setopt($ch,CURLOPT_URL,$url);
	curl_setopt($ch,CURLOPT_CUSTOMREQUEST,"POST");
	curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,FALSE);
	curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,FALSE);
	curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
	curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
	curl_setopt($ch,CURLOPT_AUTOREFERER,1);
	curl_setopt($ch,CURLOPT_POSTFIELDS,$data);
	curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
	$return = curl_exec($ch);
	if(curl_errno($ch)){
		echo curl_error($ch);
	}

	curl_close($ch);

	return $return;
}


/**
 * $type:1 just check format  2:full check
 * 验证名字是否重复 分别在两个客户池
 * @param unknown $name
 * @return unknown
 */
function checkname($url_base,$name,$type) {
	if($type==1)
		$url = $url_base."/microhifo/checkFormatName";
	elseif($type==2)
		$url = $url_base."/microhifo/checkName";

	$post_data = array ("name" => $name);

	$result = postData ( $url, $post_data );
	return $result;
}


/**
 * 验证电话 分别在两个客户池
 * $type:1 just check format  2:full check
 */
function checkphone($url_base,$phone,$type) {
	if($type==1)
		$url = $url_base."/microhifo/checkFormatPhone";
	elseif ($type==2)
		$url = $url_base."/microhifo/checkPhone";

	$post_data = array ("phone" => $phone);

	$result = postData ( $url, $post_data );
	return $result;
}

/**
 * 验证身份证号码
 */
function checkidcard($url_base,$idCard) {
	$url = $url_base."/microhifo/checkIdCard";

	$post_data = array ("idCard" => $idCard);

	$result = postData ( $url, $post_data );
	return $result;
}

/**
 *
 * @param unknown $url
 * @param unknown $code
 * @param unknown $type
 */
function getAddressList($url_base,$code,$type){
	$result = null;
	if($type==null)
		return false;
		if($type==1){	//获取所有的省
			$url = $url_base."/microhifo/getProvince";

		}elseif ($type==2){	//获取市
			$url = $url_base."/microhifo/getCity";

		}elseif($type==3){ //获取地区
			$url = $url_base."/microhifo/getArea";
		}
		$post_data = array ("code" => $code); //传参数
		$result = postData($url, $post_data);
		return $result;
}